import React, { useEffect } from 'react';
import { Form, Input, Button } from 'antd';

interface EditProfileFormProps {
  user: {
    name: string;
    email: string;
    phone: string;
    address: string;
  };
  onSave: (user: { name: string; email: string; phone: string; address: string }) => void;
  onCancel: () => void;
}

const EditProfileForm: React.FC<EditProfileFormProps> = ({ user, onSave, onCancel }) => {
  const [form] = Form.useForm();

  useEffect(() => {
    form.setFieldsValue(user);
  }, [user, form]);

  const onFinish = (values: { name: string; email: string; phone: string; address: string }) => {
    onSave(values);
  };

  return (
    <Form form={form} layout="vertical" onFinish={onFinish}>
      <Form.Item name="name" label="姓名" rules={[{ required: true, message: '请输入姓名' }]}>
        <Input />
      </Form.Item>
      <Form.Item name="email" label="邮箱" rules={[{ required: true, message: '请输入邮箱' }]}>
        <Input />
      </Form.Item>
      <Form.Item name="phone" label="电话" rules={[{ required: true, message: '请输入电话' }]}>
        <Input />
      </Form.Item>
      <Form.Item name="address" label="地址" rules={[{ required: true, message: '请输入地址' }]}>
        <Input />
      </Form.Item>
      <Form.Item>
        <Button type="primary" htmlType="submit">
          保存
        </Button>
        <Button style={{ marginLeft: '8px' }} onClick={onCancel}>
          取消
        </Button>
      </Form.Item>
    </Form>
  );
};

export default EditProfileForm;